import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { defHttp } from '/@/utils/http/axios';
import { rules } from '/@/utils/helper/validator';
import { render, formattingMin, formattingDay } from '/@/utils/common/renderUtils';
//列表数据
export const columns : BasicColumn[] = [
	{
		title: '订单状态',
		align: "center",
		dataIndex: 'stats',
		customRender: ({ text }) => {
			if (text == 'Waitpay') {
				return '报名待付款'
			} else if (text == 'Mark') {
				return '候选待付款'
			} else if (text == 'Join') {
				return '已入团'
			} else if (text == 'Payback') {
				return '已退款'
			} else if (text == 'Out') {
				return '已离开'
			} else if (text == 'Timeout') {
				return '超时退出'
			} else if (text == 'Finished') {
				return '已完成'
			} else if (text == 'Dispatched') {
				return '已调度'
			} else if (text == 'Payed') {
				return '已支付'
			}else if (text == 'WaitEval') {
				return '待评价'
			}else if (text == 'WaitTravel') {
				return '待出行'
			}
		}
	},
	{
		title: '用户',
		align: "center",
		dataIndex: 'userid_dictText'
	},
	/* {
	 title: '旅游拼团ID',
	 align:"center",
	 dataIndex: 'travelgroupid'
	}, */
	{
		title: '付款截止时间',
		align: "center",
		dataIndex: 'payexpiretime',
		customRender: ({ text }) => {
			return formattingMin(text)
		}
	},
	{
		title: '提交报名时间',
		align: "center",
		dataIndex: 'createtime',
		customRender: ({ text }) => {
			return formattingMin(text)
		}
	},
	{
		title: '是否已签合同',
		align: "center",
		dataIndex: 'signcontract',
		customRender: ({ text }) => {
			if (text == true) {
				return '是'
			} else {
				return '否'
			}
		}
	},
	{
		title: '待付款金额，原价',
		align: "center",
		dataIndex: 'originprice'
	},
	{
		title: '减去退款后最终金额',
		align: "center",
		dataIndex: 'finalprice'
	}, 
	{
		title: '上车地',
		align: "center",
		dataIndex: 'upCarPoint',
		customRender: ({ text }) => {
			if (text) {
				let o = JSON.parse(text)
				return o.address
			}
		},
		ellipsis: true
	},
	/* {
		title: '操作历史',
		align: "center",
		dataIndex: 'ctlhistory'
	},
	{
		title: '其余信息',
		align: "center",
		dataIndex: 'extinfor'
	}, */
];
//查询数据
export const searchFormSchema : FormSchema[] = [
];
//表单数据
export const formSchema : FormSchema[] = [
	{
		label: '订单状态',
		field: 'stats',
		component: 'JDictSelectTag',
		componentProps: {
			dictCode: "tour_order_stats"
		},
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请选择订单状态!' },
			];
		},
	},
	{
		label: '用户',
		field: 'userid',
		component: 'JSearchSelect',
		componentProps: {
			dict: 'BS_UserLayout_UserInfor,phone,id',
			pageSize: 10
		},
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入用户ID!' },
			];
		},
	},
	/* 	{
			label: '旅游拼团ID',
			field: 'travelgroupid',
			component: 'Input',
			dynamicRules: ({ model, schema }) => {
				return [
					{ required: true, message: '请输入旅游拼团ID!' },
				];
			},
		}, 
		{
			label: '付款截止时间',
			field: 'payexpiretime',
			component: 'Input',
			dynamicRules: ({ model, schema }) => {
				return [
					{ required: true, message: '请输入付款截至时间!' },
				];
			},
		},
		{
			label: '创建时间',
			field: 'createtime',
			component: 'Input',
			dynamicRules: ({ model, schema }) => {
				return [
					{ required: true, message: '请输入创建时间!' },
				];
			},
		},*/
	{
		label: '是否已签合同',
		field: 'signcontract',
		component: 'JDictSelectTag',
		componentProps: {
			dictCode: 'is_true'
		},
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请选择是否已签合同!' },
			];
		},
	},
	{
		label: '待付款金额，原支付金额',
		field: 'originprice',
		component: 'InputNumber',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入待付款金额，原价!' },
			];
		},
	},
	{
		label: '减去退款后最终金额',
		field: 'finalprice',
		component: 'InputNumber',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入减去退款后最终金额!' },
			];
		},
	},
	{
		label: '',
		field: 'mainId',
		component: 'Input',
		show: false
	},
	{
		label: '上车地点',
		field: 'startpoint',
		component: 'ApiSelect',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入上车地!' },
			];
		},
		componentProps: ({ formActionType, formModel }) => {
			console.log(formModel.mainId)
			if (formModel.mainId) {
				return {
					//multiple: 多选；不填写为单选
					mode: '',
					//根据大团id获取上车地点
					//请求api,返回结果{ result: { records: [{'id':'1',name:'scott'},{'id':'2',name:'小张'}] }}
					api: () => defHttp.get({ url: '/journey/bsTravelgroupMaintuortravellinerecord/getUpCarAddressById?id=' + formModel.mainId }),
					//数值转成String
					numberToString: false,
					//标题字段
					labelField: 'address',
					//值字段
					valueField: 'upCatPointId',
					//请求参数
					params: {
						//carpoolBus: formModel.carpoolBus
					},
					//返回结果字段
					resultField: 'records'
				}
			}
		},
	},
	//选酒店：根据游玩天数选酒店类型

	{
		label: '选择住宿',
		field: 'stayTypeId',
		component: 'ApiSelect',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入上车地!' },
			];
		},
		componentProps: ({ formActionType, formModel }) => {
			if (formModel.mainId) {
				return {
					//multiple: 多选；不填写为单选
					mode: '',
					//根据大团id获取上车地点
					//请求api,返回结果{ result: { records: [{'id':'1',name:'scott'},{'id':'2',name:'小张'}] }}
					api: () => defHttp.get({ url: '/journey/bsTravelgroupMaintuortravellinerecord/getStayTypesById?id=' + formModel.mainId }),
					//数值转成String
					numberToString: false,
					//标题字段
					labelField: 'leveltitle',
					//值字段
					valueField: 'id',
					//请求参数
					params: {
						//carpoolBus: formModel.carpoolBus
					},
					//返回结果字段
					resultField: 'records'
				}
			}
		},
	},
	{
		label: '附加产品',
		field: 'pdtId',
		component: 'ApiSelect',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入上车地!' },
			];
		},
		componentProps: ({ formActionType, formModel }) => {
			if (formModel.mainId) {
				return {
					//multiple: 多选；不填写为单选
					mode: '',
					//根据大团id获取上车地点
					//请求api,返回结果{ result: { records: [{'id':'1',name:'scott'},{'id':'2',name:'小张'}] }}
					api: () => defHttp.get({ url: '/journey/bsTravelgroupMaintuortravellinerecord/getPdtsById?id=' + formModel.mainId }),
					//数值转成String
					numberToString: false,
					//标题字段
					labelField: 'title',
					//值字段
					valueField: 'id',
					//请求参数
					params: {
						//carpoolBus: formModel.carpoolBus
					},
					//返回结果字段
					resultField: 'records'
				}
			}
		},
	},

	{
		label: '选择保险',
		field: 'insuranceId',
		component: 'JDictSelectTag',
		componentProps: {
			dictCode: 'BS_InsuranceData,title,id'
		},
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请选择保险险种!' },
			];
		},
	},

	/* 	{
			label: '操作历史',
			field: 'ctlhistory',
			component: 'InputTextArea',
			dynamicRules: ({ model, schema }) => {
				return [
					{ required: true, message: '请输入操作历史!' },
				];
			},
		}, 
		{
			label: '其余信息',
			field: 'extinfor',
			component: 'InputTextArea',
			dynamicRules: ({ model, schema }) => {
				return [
					{ required: true, message: '请输入其余信息!' },
				];
			},
		},*/
	// TODO 主键隐藏字段，目前写死为ID
	{
		label: '',
		field: 'id',
		component: 'Input',
		show: false
	},

];



/**
* 流程表单调用这个方法获取formSchema
* @param param
*/
export function getBpmFormSchema(_formData) : FormSchema[] {
	// 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
	return formSchema;
}